package org.feng.framework.security;

import cn.dev33.satoken.stp.StpInterface;
import lombok.AllArgsConstructor;
import org.feng.service.MenuService;
import org.feng.service.UserService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 冯帅
 * @des 用户权限设置
 * @date 2021/11/29 14:28
 * @email 15612509687@163.com
 */
@Component
@AllArgsConstructor
public class ApiAuth implements StpInterface {

    private final UserService userService;
    private final MenuService menuService;

    /**
     * 设置用户权限
     *
     * @param loginId   登录id
     * @param loginType 登录类型
     * @return 权限列表
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        HashMap<String, Boolean> map = menuService.getAuthButtons();
        ArrayList<String> list = new ArrayList<>();
        for (Map.Entry<String, Boolean> entry : map.entrySet()) {
            if (entry.getValue()) {
                list.add(entry.getKey());
            }
        }
        return list;
    }

    /**
     * 设置用户角色
     *
     * @param loginId   登录id
     * @param loginType 登录类型
     * @return 角色列表
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return new ArrayList<>();
    }
}
